package com.kylin.upms.biz.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.kylin.upms.biz.entity.UserRole;
import com.kylin.upms.biz.service.IUserRoleService;
import com.kylin.upms.biz.vo.ResEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2019-09-15
 */
@RestController
@RequestMapping("/userRole")
public class UserRoleController {
    @Autowired
    IUserRoleService iUserRoleService;
    @CrossOrigin(origins = {"http://localhost:8081"})
    @RequestMapping(value = "/updRoleByUser",method = RequestMethod.GET)
    public ResEntity updRoleByUser(Integer uid, Integer[] rids){
        UserRole userRole = new UserRole();
        userRole.setUid(uid);
        EntityWrapper entityWrapper = new EntityWrapper(userRole);
        iUserRoleService.delete(entityWrapper);
        for (Integer rid : rids) {

            userRole.setRid(rid);

            boolean insert = iUserRoleService.insert(userRole);
        }
        return ResEntity.ok("插入成功");
    }
}
